using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Game500.Client.Src.Logic
{
  internal class ShadowDrawer
  {
    private readonly Texture2D myShadowTexture;

    public ShadowDrawer(ResourceManager resourceManager)
    {
      myShadowTexture = resourceManager.GetTexture("planeShadow.png");
    }

    public void DrawShadow(Renderable renderable, Renderer renderer)
    {
      Vector3 pos = renderable.Position;
      pos.Y = 0;
      pos.Z += float.Epsilon;
      var width = (float)Math.Cos(renderable.Rotation);

      float alpha = .8f;
      const float shadowHeightLimit = 80;
      if (renderable.Y > shadowHeightLimit) alpha = 0;
      else
      {
        alpha *= 1.0f - renderable.Y / shadowHeightLimit;
      }
      renderer.RenderSprite(myShadowTexture, pos, new Vector2(0.5f, -0.5f), new Vector2(width, 1), new Color(1.0f, 1, 1, alpha));
    }
  }
}